package com.hse.network;

import com.hse.application.ApplicationLayerException;
import com.hse.application.ApplicationMacStackLayer;
import com.hse.network.exceptions.NetworkException;

public class CoordinatorClient implements ICoordinatorClient {
    private ApplicationMacStackLayer mac;
    private Short clientAddress;
    private Short coordinatorAddress;
    private Short panId;

    public CoordinatorClient(ApplicationMacStackLayer mac, Short panId,
                             Short clientAddress, Short coordinatorAddress) {
        this.mac = mac;
        this.clientAddress = clientAddress;
        this.coordinatorAddress = coordinatorAddress;
        this.panId = panId;
    }

    public void send(byte[] data) throws NetworkException {
        try {
            mac.send(panId, coordinatorAddress, clientAddress, data);
        } catch (ApplicationLayerException e) {
            throw new NetworkException(e);
        }
    }

    public byte[] recv() {
        return mac.recv(panId, clientAddress, coordinatorAddress);
    }

    public boolean canRead() {
        return mac.canRead(panId, clientAddress, coordinatorAddress);
    }
}
